<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>星星评分</title>
    <script>
        window.onload=function(){
            var imgs=document.getElementsByTagName("img");
            for(var i=0;i<imgs.length;i++){
                imgs[i].setAttribute("score",i+1);
                imgs[i].onclick=function(){

                    var srcEl=event.srcElement;

                    var score=srcEl.getAttribute("score");
                    for(var j=0;j<score;j++){
                        imgs[j].src="img/b015df4c7ddb8888d3be4c8bed7c87f1_03.jpg";
                    }
                    for(var j=score;j<imgs.length;j++){
                        imgs[j].src="img/b015df4c7ddb8888d3be4c8bed7c87f1_04.jpg";
                    }
                    document.getElementById("lab").innerHTML=srcEl.getAttribute("score");//通过srcEl调用getAttribute方法获取分数
                }
            }
        }
    </script>
</head>
<body>
    <img src="img/b015df4c7ddb8888d3be4c8bed7c87f1_04.jpg">
    <img src="img/b015df4c7ddb8888d3be4c8bed7c87f1_04.jpg">
    <img src="img/b015df4c7ddb8888d3be4c8bed7c87f1_04.jpg">
    <img src="img/b015df4c7ddb8888d3be4c8bed7c87f1_04.jpg">
    <img src="img/b015df4c7ddb8888d3be4c8bed7c87f1_04.jpg">
    <label id="lab">0</label>分
</body>
</html>